package com.wei;

import java.util.HashMap;
import java.util.Map;

//  抽象原型类
public class AbstractPrototype implements Cloneable {
    private Integer id;
    private String name;
    private Map<String, Double> scores;


    /**
     * 克隆自身的方法
     */
    @Override
    public AbstractPrototype clone() {
        AbstractPrototype prototype = null;
        try {
            //  浅克隆
            prototype = (AbstractPrototype) super.clone();
            //  深克隆
            prototype.scores = (Map<String, Double>) ((HashMap) this.scores).clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return prototype;
    }

    public AbstractPrototype(Integer id, String name, Map<String, Double> scores) {
        this.id = id;
        this.name = name;
        this.scores = scores;
    }

    public AbstractPrototype() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map<String, Double> getScores() {
        return scores;
    }

    public void setScores(Map<String, Double> scores) {
        this.scores = scores;
    }

    @Override
    public String toString() {
        return "AbstractPrototype{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", scores=" + scores +
                '}';
    }
}
